package com.baidumap.administrator.happystudy.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.baidumap.administrator.happystudy.base.MyGridView;
import com.baidumap.administrator.happystudy.R;
import com.baidumap.administrator.happystudy.ui.GoodDetailActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * author: C on 2017/3/21.
 * 分类：右边
 */
public class TypeRightAdapter extends BaseAdapter{

    private Context mContext;
    private List<String> datas = null;

    public TypeRightAdapter(Context context) {
        mContext = context;
        datas = new ArrayList<>();
        datas.add("智能设备");
        datas.add("数码配件");
        datas.add("电子周边");
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_type_right, null);
            viewHolder = new ViewHolder();
            viewHolder.tvTitle = (TextView)convertView.findViewById(R.id.tv_title);
            viewHolder.mGridView = (MyGridView)convertView.findViewById(R.id.gv1);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder)convertView.getTag();
        }
        viewHolder.tvTitle.setText(datas.get(position));
        viewHolder.mGridView.setAdapter(new MyGridViewAdapter(mContext));

        viewHolder.mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(mContext, GoodDetailActivity.class);
                mContext.startActivity(intent);
            }
        });
        return convertView;
    }
    class ViewHolder {
        private TextView tvTitle;
        private MyGridView mGridView;
    }
}
